package com.hserver.deploy.event;

import com.hserver.deploy.bean.Msg;
import com.hserver.deploy.service.IndexService;
import com.hserver.deploy.websocket.DataWebSocket;
import top.hserver.core.ioc.annotation.Autowired;
import top.hserver.core.ioc.annotation.event.Event;
import top.hserver.core.ioc.annotation.event.EventHandler;
import top.hserver.core.server.context.ConstConfig;

import java.util.Map;

/**
 * 部署是一个延时过程，此时还是走这个队列比较好
 */
@EventHandler
public class DeployEvent {

    @Autowired
    private IndexService indexService;

    @Event("/deploy")
    public void deploy(Map map) {
        try {
            String uuid = map.get("uuid").toString();
            indexService.deploy(s-> DataWebSocket.sendMsg(uuid, ConstConfig.OBJECT_MAPPER.writeValueAsString(new Msg(uuid,"deploy",s))),uuid);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
